<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>无重复字符的最长子串 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 12px 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .code-dots {
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        .keyword { color: #c586c0; }
        .type { color: #4ec9b0; }
        .function { color: #dcdcaa; }
        .variable { color: #9cdcfe; }
        .string { color: #ce9178; }
        .comment { color: #6a9955; }
        .number { color: #b5cea8; }
        .operator { color: #d4d4d4; }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto animate-fadeInUp">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">
                    无重复字符的最长子串
                </h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                    探索滑动窗口算法的优雅之美，掌握字符串处理的核心技巧
                </p>
                <div class="mt-8 flex justify-center gap-6">
                    <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                        <i class="fas fa-clock mr-2"></i>
                        时间复杂度 O(n)
                    </span>
                    <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                        <i class="fas fa-memory mr-2"></i>
                        空间复杂度 O(min(m,n))
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-16">
        <!-- Problem Description -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.2s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-center mb-6">
                    <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-question-circle text-purple-600 text-xl"></i>
                    </div>
                    <h2 class="text-3xl font-bold text-gray-800">题目描述</h2>
                </div>
                <p class="text-lg text-gray-700 leading-relaxed mb-6">
                    给定一个字符串，请你找出其中不含有重复字符的最长子串的长度。
                </p>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-gray-50 rounded-lg p-6">
                        <h3 class="font-semibold text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i>
                            示例 1
                        </h3>
                        <p class="text-gray-700">
                            <span class="font-mono bg-gray-200 px-2 py-1 rounded">输入：</span> "abcabcbb"<br>
                            <span class="font-mono bg-gray-200 px-2 py-1 rounded">输出：</span> 3<br>
                            <span class="text-sm text-gray-600 mt-2 block">最长子串是 "abc"</span>
                        </p>
                    </div>
                    <div class="bg-gray-50 rounded-lg p-6">
                        <h3 class="font-semibold text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i>
                            示例 2
                        </h3>
                        <p class="text-gray-700">
                            <span class="font-mono bg-gray-200 px-2 py-1 rounded">输入：</span> "bbbbb"<br>
                            <span class="font-mono bg-gray-200 px-2 py-1 rounded">输出：</span> 1<br>
                            <span class="text-sm text-gray-600 mt-2 block">最长子串是 "b"</span>
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Core Concepts -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.4s;">
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-center mb-6">
                    <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-lightbulb text-indigo-600 text-xl"></i>
                    </div>
                    <h2 class="text-3xl font-bold text-gray-800">核心算法</h2>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-gradient-to-br from-purple-50 to-indigo-50 rounded-lg p-6">
                        <h3 class="text-xl font-semibold text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-window-restore text-purple-600 mr-3"></i>
                            滑动窗口
                        </h3>
                        <p class="text-gray-700 leading-relaxed">
                            维护一个动态的窗口，通过移动左右边界来寻找最长的无重复子串。右指针不断向右扩展，遇到重复字符时左指针向右收缩。
                        </p>
                    </div>
                    <div class="bg-gradient-to-br from-blue-50 to-cyan-50 rounded-lg p-6">
                        <h3 class="text-xl font-semibold text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-hashtag text-blue-600 mr-3"></i>
                            哈希表
                        </h3>
                        <p class="text-gray-700 leading-relaxed">
                            使用哈希表记录每个字符的最新位置，快速判断字符是否重复，并确定窗口左边界的更新位置。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Algorithm Visualization -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.6s;">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <div class="flex items-center mb-6">
                    <div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-project-diagram text-green-600 text-xl"></i>
                    </div>
                    <h2 class="text-3xl font-bold text-gray-800">算法流程图</h2>
                </div>
                <div class="mermaid">
                    graph TD
                        A[开始] --> B[初始化左右指针和哈希表]
                        B --> C{右指针是否到达末尾?}
                        C -->|否| D[获取右指针字符]
                        D --> E{字符是否在窗口中?}
                        E -->|是| F[更新左指针位置]
                        E -->|否| G[更新最大长度]
                        F --> H[更新字符位置]
                        G --> H
                        H --> I[右指针右移]
                        I --> C
                        C -->|是| J[返回最大长度]
                        J --> K[结束]
                        
                        style A fill:#f9f,stroke:#333,stroke-width:2px
                        style K fill:#9f9,stroke:#333,stroke-width:2px
                        style E fill:#ff9,stroke:#333,stroke-width:2px
                </div>
            </div>
        </section>

        <!-- Solution Code -->
        <section class="mb-16 animate-fadeInUp" style="animation-delay: 0.8s;">
            <div class="bg-white rounded-2xl shadow-lg overflow-hidden">
                <div class="p-8 pb-0">
                    <div class="flex items-center mb-6">
                        <div class="w-12 h-12 bg-orange-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-code text-orange-600 text-xl"></i>
                        </div>
                        <h2 class="text-3xl font-bold text-gray-800">示例代码</h2>
                    </div>
                </div>
                <div class="code-block mx-8 mb-8">
                    <div class="code-header">
                        <div class="code-dots">
                            <div class="dot dot-red"></div>
                            <div class="dot dot-yellow"></div>
                            <div class="dot dot-green"></div>
                        </div>
                        <span class="text-gray-400 text-sm">Java</span>
                    </div>
                    <pre><code><span class="keyword">public</span> <span class="type">int</span> <span class="function">lengthOfLongestSubstring</span>(<span class="type">String</span> <span class="variable">s</span>) {
    <span class="comment">// 创建哈希表，记录每个字符最后出现的位置</span>
    <span class="type">Map</span>&lt;<span class="type">Character</span>, <span class="type">Integer</span>&gt; <span class="variable">charIndex</span> = <span class="keyword">new</span> <span class="type">HashMap</span>&lt;&gt;();
    
    <span class="comment">// 最长无重复子串的长度</span>
    <span class="type">int</span> <span class="variable">maxLength</span> = <span class="number">0</span>;
    
    <span class="comment">// 滑动窗口的左边界</span>
    <span class="type">int</span> <span class="variable">left</span> = <span class="number">0</span>;
    
    <span class="comment">// 遍历字符串，右指针不断向右移动</span>
    <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">right</span> = <span class="number">0</span>; <span class="variable">right</span> &lt; <span class="variable">s</span>.<span class="function">length</span>(); <span class="variable">right</span>++) {
        <span class="type">char</span> <span class="variable">currentChar</span> = <span class="variable">s</span>.<span class="function">charAt</span>(<span class="variable">right</span>);
        
        <span class="comment">// 如果当前字符已经在滑动窗口中出现过，更新左边界</span>
        <span class="keyword">if</span> (<span class="variable">charIndex</span>.<span class="function">containsKey</span>(<span class="variable">currentChar</span>) && 
            <span class="variable">charIndex</span>.<span class="function">get</span>(